473,434 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

Javascript file compactor wanted

Hi,

Is there any tool that will concatinate JavaScript files compacting them
spacewise and removing comment fields ?

I have some sed script that sort of does the job but was wondering if there
were any hopefully open source tools that will do the job.

I don't want encryption or obverscation though.

Many thanks in advance,

Aaron
Jan 6 '07 #1
6 2562

Aaron Gray wrote:
Hi,

Is there any tool that will concatinate JavaScript files compacting them
spacewise and removing comment fields ?

I have some sed script that sort of does the job but was wondering if there
were any hopefully open source tools that will do the job.

I don't want encryption or obverscation though.
<URL: http://www.crockford.com/javascript/jsmin.html>

Jan 6 '07 #2
Aaron Gray wrote:
Hi,

Is there any tool that will concatinate JavaScript files compacting them
spacewise and removing comment fields ?

I have some sed script that sort of does the job but was wondering if there
were any hopefully open source tools that will do the job.

I don't want encryption or obverscation though.

Many thanks in advance,

Aaron


If you have access to your .htaccess file on your web server then you
can use some rewrite rules to send external javascript files as
compressed gzip files. The browser will send a header if it can accept
gzip compression (most every browser can), if it can just pass it the
script.js.gz file and if it can't have the rewrite engine pass the
script.js file.

You'll not get better throughput any other way (and you can leave your
js files mostly readable since you don't have to strip whitespace).

--
http://www.hunlock.com -- Musings in Javascript, CSS.
$FA
Jan 6 '07 #3
pcx99 wrote:
Aaron Gray wrote:
Is there any tool that will concatinate JavaScript files compacting them
spacewise and removing comment fields ?

I have some sed script that sort of does the job but was wondering if there
were any hopefully open source tools that will do the job.

I don't want encryption or obverscation though.

Many thanks in advance,

Aaron


If you have access to your .htaccess file on your web server then you
can use some rewrite rules to send external javascript files as
compressed gzip files. The browser will send a header if it can accept
gzip compression (most every browser can), if it can just pass it the
script.js.gz file and if it can't have the rewrite engine pass the
script.js file.

You'll not get better throughput any other way (and you can leave your
js files mostly readable since you don't have to strip whitespace).
To get the best results use both minimization and compression together.
The reason both are useful is there is no need to compress and send the
comments or whitespace.

<URL: http://yuiblog.com/blog/2006/10/16/pageweight-yui0114/>

It also helps to reduce the number of JavaScript files by concatenating
them together

<URL: http://yuiblog.com/blog/2006/11/28/performance-research-part-1/>

Peter

Jan 6 '07 #4
Peter Michaux wrote:
pcx99 wrote:
>Aaron Gray wrote:
>>Is there any tool that will concatinate JavaScript files compacting them
spacewise and removing comment fields ?

I have some sed script that sort of does the job but was wondering if there
were any hopefully open source tools that will do the job.

I don't want encryption or obverscation though.

Many thanks in advance,

Aaron

If you have access to your .htaccess file on your web server then you
can use some rewrite rules to send external javascript files as
compressed gzip files. The browser will send a header if it can accept
gzip compression (most every browser can), if it can just pass it the
script.js.gz file and if it can't have the rewrite engine pass the
script.js file.

You'll not get better throughput any other way (and you can leave your
js files mostly readable since you don't have to strip whitespace).

To get the best results use both minimization and compression together.
The reason both are useful is there is no need to compress and send the
comments or whitespace.

<URL: http://yuiblog.com/blog/2006/10/16/pageweight-yui0114/>

It also helps to reduce the number of JavaScript files by concatenating
them together

<URL: http://yuiblog.com/blog/2006/11/28/performance-research-part-1/>

Peter
I just fooled around with the rewrite engine and took my 10k common JS
file and created a gz version (didn't even tweak the settings) and it's
now a 3k file. The rewrite engine puts a performance hit on the server
but that is MORE than overcome by the bandwidth (and to a far lesser
extent) storage space savings. It won't work for php files but for any
static html or ANY static file be it .js, .css, etc it will work
invisibly and transparently. Just drop a gz copy of the file alongside
the original and if the browser can handle it the server will send the
compressed file...

RewriteEngine on
RewriteOptions Inherit

#Check to see if browser can accept gzip files.
ReWriteCond %{HTTP:accept-encoding} (gzip.*)

#make sure there's no trailing .gz on the url
#ReWriteCond %{REQUEST_FILENAME} !^.+\.gz$

#check to see if a .gz version of the file exists.
RewriteCond %{REQUEST_FILENAME}.gz -f

#All conditions met so add .gz to URL filename (invisibly)
RewriteRule ^(.+) $1.gz [L]
--
http://www.hunlock.com -- Musings in Javascript, CSS.
$FA
Jan 6 '07 #5
Rik
pcx99 wrote:
I just fooled around with the rewrite engine and took my 10k common JS
file and created a gz version (didn't even tweak the settings) and
it's
now a 3k file. The rewrite engine puts a performance hit on the
server
but that is MORE than overcome by the bandwidth (and to a far lesser
extent) storage space savings. It won't work for php files but for
any static html or ANY static file be it .js, .css, etc it will work
invisibly and transparently.
The output of a php file can also easily be gzipped, by using either
ob_gzhandler() or zlib.output_compression. Zipping the source is somewhat
useless as it doesn't get send anyway.
--
Rik Wasmus
Jan 6 '07 #6
Thanks Guys I will check these options out.

Many thanks,

Aaron
Jan 6 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mydirac | last post by:
hello, I'm thinking about javascript's producing another file. Can I do it?
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
10
by: VictorG | last post by:
Hello, I am new to JS and am trying to add some HTML into a JS function. So that when called the script as well as the HTML will be invoked. Is there some type of embed mechanism, sort of the...
9
by: Robby Bankston | last post by:
I'm working on some code and am running into brick walls. I'm trying to write out Javascript with Javascript and I've read the clj Meta FAQ and didn't see the answer, read many similar posts (with...
21
by: strutsng | last post by:
<input type="file"> only allows the user to browse for files. How about "browse for folder" dialog? Can html/javascript do that? I couldn't find any syntax for that. If not, please advise what...
24
by: gizoto316 | last post by:
I was wondering if it was possible to have php code in a javascript file. I have a java file with a bunch of functions on it and I wanted to add one where the action has php code in it. When i...
8
by: Frank | last post by:
Hi, I am working with VS.NET 2005 Ultimately, I wish to call a JavaScript function from a .js file
3
by: wbazarin | last post by:
I am very new using javascript and I faced a problem that with my expertise I cannot solve. I wrote a small html file that handle a vertical menu. I wrote a function to show the menu correctly using...
2
hsriat
by: hsriat | last post by:
For a good programmer, providing good comments in the code is a must. In PHP, giving comments has no demerits. But what about JavaScript? Do you really want those comments to stay in the code and...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.